import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.webapp.WebAppContext;

/**
 * @ClassName: JettyServer
 * @Description: 开发调试使用的 Jetty Server
 * @author: 神奇的鸭鸭
 * @Date: 2017/12/6 14:04
 */
public class JettyServer {

    static final String absloute_path = "E:\\MyCode\\oscGit\\AcmenMS\\AcmenMS-web\\";

    public static void main(String[] args) throws Exception {
        Server server = buildNormalServer(8091, "/");
        server.start();
    }

    /**
     * 创建用于正常调试Jetty Server，以src/main/webapp为web应用目录
     */
    private static Server buildNormalServer(int port, String contextPath) {
        Server server = new Server(port);

        WebAppContext webContext = new WebAppContext(absloute_path + "src/main/webapp", contextPath);
        webContext.setClassLoader(Thread.currentThread().getContextClassLoader());
        webContext.setMaxFormContentSize(-1);
        ContextHandlerCollection handler = new ContextHandlerCollection();
        handler.addHandler(webContext);
        server.setHandler(handler);
        server.setStopAtShutdown(true);
        return server;
    }
}